<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>佣金转余额</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form class="layui-form update_form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">佣金</label>
				<div class="layui-input-block update_shurk">
					<input type="text" value="{$agent_info['commission']}" placeholder="23423元,（提现到余额扣除5%服务费）" class="layui-input" disabled="disabled">

				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">需要转</label>
				<div class="layui-input-block update_shurk">
					<input type="text" onkeyup="clearNoNum(this)" id='commission'  name="commission" required lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

</html>
<script>
	//只能数字和小数点
	function clearNoNum(obj) {
		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}
	
	function to_money(){
		var cut_commission = "{$agent_info['commission']}";
		var to_num = $('#commission').val();
		
		if(to_num < 10){
			layer.msg('金额不能小于10！');
			return ;
		}
		
		if(to_num > parseFloat(cut_commission)){
			layer.msg('佣金不足！');
			return ;
		}
		$.ajax({
             	type:"post",
                url:"{:url('agent/index/yongj_yue')}",
                data: {
                	commission	: $('#commission').val()
                },
                success:function(data){
                   layer.msg(data.msg, {
						  icon: 1,
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							parent.location.reload();
						});
                },error:function(data){
                	var a = data;
                }
        });
	}
	
	//Demo
	layui.use('form', function() {
		var form = layui.form;

		//监听提交
		form.on('submit(formDemo)', function(data) {
			//layer.msg(JSON.stringify(data.field));
			to_money();
			return false;
		});
	});
</script>